﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace AIStudio.Wpf.EasyTileManager.Utils
{
    /// <summary>
    /// 按比率转换宽度
    /// </summary>
    public class RatioWidthConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double result = 0.0;
            double rate = 1.0;

            if (value == null)
            {
                return result;
            }

            if (parameter != null)
            {
                if (double.TryParse(parameter.ToString(), out rate))
                {

                }
            }

            if (double.TryParse(value.ToString(), out result))
            {
                result *= rate;
            }

            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }

    public class stateToCollapsededGlyphVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return System.Windows.Visibility.Visible;
            }

            TileState result = TileState.Normal;

            if (Enum.TryParse(value.ToString(), out result))
            {
                if (result == TileState.Normal)
                {
                    return System.Windows.Visibility.Visible;
                }
                else
                {
                    return System.Windows.Visibility.Hidden;
                }
            }

            return System.Windows.Visibility.Hidden;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }

    public class stateToExpandedGlyphVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return System.Windows.Visibility.Visible;
            }

            TileState result = TileState.Normal;

            if (Enum.TryParse(value.ToString(), out result))
            {
                if (result == TileState.Normal)
                {
                    return System.Windows.Visibility.Hidden;
                }
                else
                {
                    return System.Windows.Visibility.Visible;
                }
            }

            return System.Windows.Visibility.Hidden;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }

    public class TileStateToToggleVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return System.Windows.Visibility.Visible;
            }

            TileState result = TileState.Normal;

            if (Enum.TryParse(value.ToString(), out result))
            {
                switch (result)
                {
                    case TileState.Maximized:
                        {
                            return System.Windows.Visibility.Collapsed;
                        }
                    case TileState.Normal:
                    case TileState.Minimized:
                    case TileState.MinimizedExpanded:
                    default:
                        {
                            return System.Windows.Visibility.Visible;
                        }
                }
            }

            return System.Windows.Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
